<template>
    <div class="app-container">
      <div class="filter-container" style="display: flex;
      flex-direction: row-reverse;">
        <div class="lineBox">
          <el-form :inline="true" :model="listQuery" class="demo-form-inline">
            <el-form-item>
              <el-button size="mini" type="primary" @click="add">
                添加
              </el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
  
      <div class="myTable" style="min-height: 600px;">
        <el-table :key="tableKey" :data="list" fit size="mini" highlight-current-row style="width: 100%;">
          <el-table-column label="ID" prop="id" align="center" min-width="50" />
          <el-table-column label="模板名称" prop="template_name" align="center" min-width="200" />
          <el-table-column label="修改时间" prop="update_time" align="center" min-width="100" />
          <el-table-column label="识别特征" prop="identifying_features" show-overflow-tooltip align="center"
            min-width="200" />
          <el-table-column label="优先级" prop="priority" align="center" min-width="50" />
          <el-table-column label="启用状态" prop="status" align="center" min-width="100">
            <template slot-scope="{row,$index}">
              <div v-if="row.status== '1'">
                <span class="statusPie success" />
                <span class="text">是</span>
              </div>
              <div v-else>
                <span class="statusPie danger" />
                <span class="text">否</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="抽取方式" prop="mode" align="center" min-width="100">
            <template slot-scope="{row,$index}">
              <div v-if="row.mode== '1'">
                霍夫算法
              </div>
              <div v-if="row.mode== '2'">
                大模型抽取
              </div>
              <div v-if="row.mode== '3'">
                不抽取
              </div>
            </template>
          </el-table-column>
  
          <el-table-column label="操作" align="center" min-width="160" class-name="small-padding fixed-width">
            <template slot-scope="{row,$index}">
              <el-button type="primary" size="mini" @click="skip(row,$index)">
                编辑
              </el-button>
  
              <el-button size="mini" type="danger" @click="handleDelete(row,$index)">
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination size="mini" :page-sizes="[10]" :total="total" :page.sync="listQuery.page"
          :limit.sync="listQuery.limit" layout="total, sizes, prev, pager, next, jumper" @pagination="dataList" />
      </div>
    </div>
  </template>
  
  <script>
  import { api } from '@/api/template'
  import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  export default {
  
    components: { Pagination },
  
    data() {
      return {
  
        formInline: {
          user: "",
          region: ""
        },
        value: '',
  
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: false,
        listQuery: {
          pageNumber: 1,
          page: 1,
          limit: 10,
  
        },
  
  
      }
    },
  
  
  
    created() {
  
      this.dataList()
    },
    methods: {
  
      // 数据列表
      async dataList() {
        this.listLoading = true
        const response = await api("getTemplateList", this.listQuery)
        if (response.code == 200) {
          this.list = response.data.resultList
          this.total = response.totalCount
          // this.type = response.type
          //   // Just to simulate the time of the request
          setTimeout(() => {
            this.listLoading = false
          }, 1.5 * 1000)
        }
      },
  
      // 删除指标
      async handleDelete(row, index) {
        this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          const data = { 'id': row.id }
  
          const response = await api("delTemplateById", data)
          if (response.code == 200) {
            this.$notify({
              title: '成功',
              message: response.message,
              type: 'success',
              duration: 2000
            })
            this.list.splice(index, 1)
          } else {
            this.$notify({
              title: '失败',
              message: response.message,
              type: 'error',
              duration: 2000
            })
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      },
  
      // 修改跳转
      skip(row, index) {
  
        this.$router.push('/template/promptwordmanagementsave?id=' + row.id)
  
      },
      add() {
        this.$router.push('/template/promptwordmanagementsave?id')
      }
  
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .demo-image__preview {
    float: left;
    margin-left: 5px;
  }
  .demonstration {
    font-size: 12px;
    color: #333;
    font-weight: normal;
  }
  </style>
  